<template>
  <div class="playitemContent">
    <div class="tool">
      <div class="toolItem">
        <SvgView ion="#icon-shoucangjia" />
        <span>{{ changeCount(props.playlist.subscribedCount) }}</span>
      </div>
      <div class="toolItem">
        <SvgView ion="#icon-pinglun-" />
        <span>{{ changeCount(props.playlist.commentCount) }}</span>
      </div>
      <div class="toolItem">
        <SvgView ion="#icon-fenxiang" />
        <span>{{ changeCount(props.playlist.shareCount) }}</span>
      </div>
    </div>
    <div class="musicContent">
      <van-sticky>
        <div class="play">
          <div class="playLeft">
            <SvgView ion="#icon-bofang-copy" />
            <p>
              播放全部<span>({{ props.music.length }})</span>
            </p>
          </div>
          <div class="playRight">
            <SvgView ion="#icon-iconfontzhizuobiaozhun023146" />
            <SvgView ion="#icon-show_duoxuan" />
          </div>
        </div>
      </van-sticky>
      <div class="musicList">
        <div class="musicListItem" v-for="(item, index) in props.music" :key="item.id">
          <div class="itemLeft" @click="changeMusic(index)">
            <span>{{ index + 1 }}</span>
            <div class="itemName">
              <h4>{{ item.name }}</h4>
              <span>{{
                  item.ar
                    .reduce((a, b) => {
                      return (a += b.name + ",");
                    }, "")
                    .slice(0, -1)
              }}</span>
            </div>
          </div>
          <div class="itemRight">
            <SvgView ion="#icon-shipin" v-if="item.mv != 0" />
            <SvgView ion="#icon-gengduo-shuxiang" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import SvgView from "@/components/SvgView";
import { useMusicStore } from "@/store/store.js";
const musicStore = useMusicStore();
const props = defineProps({
  playlist: Object,
  music: Object,
});
const changeCount = (num) => {
  if (num > 100000000) {
    return (num / 100000000).toFixed(1) + "亿";
  } else if (num > 10000) {
    return (num / 10000).toFixed(1) + "万";
  } else {
    return num;
  }
};

const changeMusic = (idx) => {
  musicStore.changePlayList(props.music);
  musicStore.changePlayIndex(0, idx);
  musicStore.changePlayReady(true);
  musicStore.getMusicLyric();
  musicStore.changeFM(false)
  musicStore.changePlayPop(true)
};
</script>

<style scoped lang="less">
.playitemContent {
  width: 100%;
  background-color: white;
  margin-top: 50px;
  position: relative;

  .tool {
    width: 310px;
    height: 40px;
    background: white;
    position: absolute;
    left: 50%;
    margin-left: -155px;
    margin-top: -20px;
    border-radius: 50px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px,
      rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;

    .toolItem {
      display: flex;
      align-items: center;
      border-right: 1px silver solid;
      width: 100%;
      justify-content: center;
      text-align: center;
      flex: 1;

      &:last-child {
        border-right: none;
      }

      span {
        font-size: 10px;
      }
    }
  }

  .musicContent {
    width: 100%;
    padding-top: 30px;
    z-index: -3;

    .play {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: white;
      padding: 10px 0;

      .playLeft,
      .playRight {
        display: flex;
        align-items: center;
        margin: 0 5px;

        .icon {
          margin: 0 5px;
        }

        p {
          font-size: 0.4rem;

          span {
            font-size: 0.2rem;
            color: silver;
            margin-left: 5px;
          }
        }
      }
    }

    .musicList {
      margin-bottom: 50px;

      .musicListItem {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 60px;

        .itemLeft {
          display: flex;
          justify-content: space-around;
          align-items: center;
          margin: 0 10px;

          >span {
            color: silver;
            font-size: 16px;
          }

          .itemName {
            margin-left: 15px;

            h4 {
              margin-bottom: 3px;
              width: 220px;
              font-weight: bolder;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              font-size: 16px;
            }

            span {
              display: block;
              width: 150px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              color: silver;
              font-size: 8px;
            }
          }
        }

        .itemRight {
          display: flex;
          justify-content: space-around;
          align-items: center;
          margin: 0 10px;

          .icon {
            margin: 0 5px;
            width: 15px;
            height: 15px;
          }
        }
      }
    }
  }
}
</style>
